package SearchPopupwindow;

import com.csdn.leon.base.R;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.MeasureSpec;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.PopupWindow;

public class FloatPopupWindow {

	private String TAG=FloatPopupWindow.class.getSimpleName();
    private Context context;   
    private LayoutInflater inflater;
	private View mView;
	private ImageView floatView;
	private PopupWindow popupWindow;
	
	public FloatPopupWindow(Context context,View view){
		this.context=context;
		this.floatView=(ImageView)view;
		inflater=LayoutInflater.from(context);
		initView();
	}
	
	private void initView(){
		mView=inflater.inflate(R.layout.float_frament_layout,null);
		popupWindow=new PopupWindow(mView ,LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true);
		popupWindow.setBackgroundDrawable(new BitmapDrawable());
		int[] location = new int[2];
		floatView.getLocationOnScreen(location);
		
		int popupWidth = floatView.getMeasuredWidth();
		
		int popupHeight =  floatView.getMeasuredHeight();
		
		int x=location[0];
		int y=location[1];
		Log.w(TAG, "x:"+ x +"Y:"+y);
		
	//	popupWindow.showAtLocation(mView, Gravity.CENTER, 0, 0);
		popupWindow.showAtLocation(mView, Gravity.TOP, (location[0]+popupWidth/2)-80,
				location[1]-popupHeight);
		Log.w(TAG, "popupWidth:"+ popupWidth +"popupHeight:"+popupHeight);
	 }
	
}
